//渲染box属性
function setBoxPropsRender(stageWidth,parentWidth,box,props,editing){
	var showPath = $("#websiteeditor_showPath").val();
	var showImgPath = $("#websiteeditor_showImgPath").val();
	var boxElem = box.find(".elementsBox");
	var decons = boxElem.find(".decons");
	var fontsizeS = null;
	var needrenderSlidebox = false;
	//窗口高度
	var wheight =  $(window).height();
	//获取div跳转类型
	// 事件类型 1：跳转  2：在当前页面打开某个铺满全屏的iframe页面 3：父级窗口跳转内部地址
	//#--可跳转本页指定id控件  30
	//-跳转指定pageCode页面  10  
	//*t*则跳转全路径   20
	//*f*打开内部地址   40
	//*fs*打开外部地址  50
	//*p*父级窗口跳转内部地址  60 
	//*pt*父级窗口跳转外部地址  70
	//*sub*提交至指定地址  80
	var divHrefType = "";
	var childname = "";
	var name = "";
	var clickshow = "";
	var clickshowcolor = "";
	var clickcolor = "";
	var clickfontweight = "";
	for(var i = 0; i < props.length; i++){
		var prop = props[i];
		if("divhreftype" == prop.text || "iframedivhreftype" == prop.text){
			divHrefType = prop.content;//获取跳转类型
		}else if("childname" == prop.text){
			childname = prop.content;//获取子级name
		}else if("name" == prop.text){
			name = prop.content;//获取子级name
		}else if("clickshow" == prop.text){
			clickshow = prop.content;//获取子级name
		}else if("clickcolor" == prop.text){
			clickcolor = prop.content;//获取子级name
		}else if("clickshowcolor" == prop.text){
			clickshowcolor = prop.content;//获取子级name
		}else if("clickfontweight" == prop.text){
			clickfontweight = prop.content;//获取子级name
		}
	}
	
	for(var i = 0; i < props.length; i++){
		var prop = props[i];
		if("1" == prop.type){
			var propcontent = prop.content;
			var ttext = prop.text;
			if("src" == prop.text){
				ttext = "src";
				if(null != propcontent && "" !=propcontent && undefined != propcontent && "undefined" != propcontent){
					if("40" == divHrefType){
						//打开iframe
						propcontent = showPath + propcontent;
						//编辑模式下加一个遮罩层，方便编辑选中
						if(editing){
							if(boxElem.find(".iframezzc").size() == 0){
								boxElem.append("<div class='iframezzc' name='"+name+"' style='position:absolute;width:100%;height:100%;left:0px;top:0px;z-index:50000;'></div>");
							}
						}
					}else if("50" == divHrefType){
						//打开iframe外部地址
						//编辑模式下加一个遮罩层，方便编辑选中
						if(editing){
							if(boxElem.find(".iframezzc").size() == 0){
								boxElem.append("<div class='iframezzc' name='"+name+"' style='position:absolute;width:100%;height:100%;left:0px;top:0px;z-index:50000;'></div>");
							}
						}
					}else if("10" == divHrefType){
						propcontent = showPath + propcontent;
					}else{
						propcontent = showImgPath + propcontent;
					}
				}else{
					var detailCodes = boxElem.html();
					if(detailCodes.indexOf("iframe") != -1){
						//编辑模式下加一个遮罩层，方便编辑选中
						if(editing){
							if(boxElem.find(".iframezzc").size() == 0){
								boxElem.append("<div class='iframezzc' style='position:absolute;width:100%;height:100%;left:0px;top:0px;z-index:50000;'></div>");
							}
						}
					}
				}
			}else if("imgurl-o" == prop.text || "imgurl-s" == prop.text){
				ttext = "src";
				if(null != propcontent && "" !=propcontent && undefined != propcontent && "undefined" != propcontent){
					propcontent = showImgPath + propcontent;
				}
			}else if("href" == prop.text){
				if(!editing){
					// #跳转本页指定id控件 -跳转页面  其它手机操作
					if(null != propcontent && "" != propcontent){
						if("30" == divHrefType){
							propcontent = "#" + propcontent;
						}else if("10" == divHrefType){
							propcontent = showPath + propcontent;
						}else if(propcontent.indexOf("tel") != -1 || propcontent.indexOf("sms") != -1 || propcontent.indexOf("geopoint") != -1 || propcontent.indexOf("mailto") != -1){

						}else{
							propcontent = showPath + propcontent;
						}
					}else{
						if("30" == divHrefType){
							propcontent = "#";
						}else{
							propcontent = "javascript:void(0);";
						}
					}
				}else{
					propcontent = "javascript:void(0);";
				}
			}
			
			decons.attr(ttext,propcontent);
			if("class" == prop.text){
				decons.addClass("decons");
			}
		}else if("2" == prop.type){
			decons.html(prop.content);
		}else if("3" == prop.type){
			var proptext = prop.text;
			var propcontent = prop.content;
			//设定比率为1/1500
			if("font-size" == proptext){
				if(propcontent.indexOf("rem") != -1){
					decons.css(proptext,propcontent);
				}else{
					var propfont = propcontent /1500 * stageWidth;
					fontsizeS = propfont;
					propfont = propfont+"px";
					decons.css(proptext,propfont);
				}
			}else if("line-height" == proptext){
				if("normal" == propcontent || propcontent.indexOf("rem") != -1){
					decons.css(proptext,propcontent);
				}else{
					var proplh = propcontent /1500  * stageWidth;
					proplh = proplh+"px";
					decons.css(proptext,proplh);
				}
				
			}else if("border-radius" == proptext){
				if(propcontent.indexOf("rem") != -1){
					decons.css(proptext,propcontent);
				}else{
					var propbr = propcontent /1500  * stageWidth;
					propbr = propbr+"px";
					decons.css(proptext,propbr);
				}
			}else if("background-color" == proptext){
				if("#000001" == propcontent){
					propcontent = "transparent";
				}
				decons.css(proptext,propcontent);
			}else{
				decons.css(proptext,propcontent);
			}
		}else if("100" == prop.type){
			var proptext = prop.text;
			var propcontent = prop.content;
			
			if("divhref" == proptext){
				if(null != propcontent && "" != propcontent){
					var noHref = false;
					if("10" == divHrefType){
						//跳转指定pageCode页面
						propcontent = showPath + propcontent;
					}else if("20" == divHrefType){
						//跳转全路径
					}else if("30" == divHrefType){
						//跳转本页指定id控件
						propcontent = "#" + propcontent;
					}else if("40" == divHrefType){
						//打开iframe
						propcontent = showPath + propcontent;
					}else if("50" == divHrefType){
						//打开iframe  打开外部地址
					}else if("60" == divHrefType){
						//父级窗口内部跳转
						propcontent = showPath + propcontent;
					}else if("70" == divHrefType){
						//父级窗口外部全路径跳转
					}else if("80" == divHrefType){
						//表单提交
						propcontent = showPath + propcontent;
					}else if("120" == divHrefType){
						//子级窗口内部跳转
						propcontent = showPath + propcontent;
					}else if("130" == divHrefType){
						//子级窗口外部全路径跳转
					}else if("140" == divHrefType){
						//back
					}else if("150" == divHrefType){
						//跳转定制化页面
						propcontent = showPath + propcontent;
					}else if("160" == divHrefType){
						//IFRAME定制化页面
						propcontent = showPath + propcontent;
					}else{
						noHref = true;
					}
					if(!editing){
						if(!noHref){
							box.css("cursor","pointer");
						}
						var divhrefcp = propcontent;
						if("10" == divHrefType || "20" == divHrefType || "30" == divHrefType){
							box.click(function(){
								window.location.href = divhrefcp;
							});
						}else if("40" == divHrefType || "50" == divHrefType){
							box.click(function(){
								var bbox = $(this);
								var active = bbox.data("active");
								if("1" == active){
									//已点击，收起
									bbox.data("active","2");
									bbox.attr("data-actived","2");
									if($("body",window.parent.document).size() != 0){
										$("#showiframe",window.parent.document).remove();
									}else{
										$("#showiframe").remove();
									}
								}else{
									//未点击，展开
									bbox.data("active","1");
									bbox.attr("data-actived","1");
									//默认层级为30000
									var showiframe = $("<div id='showiframe' style='position:fixed;z-index:30000;left:0px;top:0px;width:100%;height:100%;'></div>");
									var iframe = $("<iframe frameborder='no' border='0' marginwidth='0' marginheight='0' " +
														" src='"+divhrefcp+"' style='position:absolute;width:100%;height:100%;left:0px;top:0px;z-index:30002;background-color:transparent;'>" +
													"</iframe>");
									var zzc = $("<div class='menuzzc'></div>");
									showiframe.append(iframe).append(zzc);
									var addType = "1";
									if($("body",window.parent.document).size() != 0){
										$("body",window.parent.document).append(showiframe);
										addType = "2";
									}else{
										$("body").append(showiframe);
									}
									if("1" == addType){
										$("#showiframe").find(".menuzzc").click(function(){
											bbox.data("active","2");
											$("#showiframe").remove();
										});
									}else if("2" == addType){
										$("#showiframe",window.parent.document).find(".menuzzc").click(function(){
											bbox.data("active","2");
											$("#showiframe",window.parent.document).remove();
										});
									}
								}
							});
						}else if("60" == divHrefType || "70" == divHrefType){
							box.click(function(){
								window.parent.window.location.href = divhrefcp;
							});
						}else if("80" == divHrefType){
							box.click(function(){
								//提交
								//序列化页面参数
								var data = {};
								var isok = true;
								$("input[actionid='"+decons.attr("id")+"']").each(function(){
									var sfbt = $(this).attr("requirement");
									var name = $(this).attr("name");
									var value = $(this).val();
									if("1" == sfbt && (null == value || "" == value || undefined == value || "undefined" == value)){
										alert(name+"必须填写！");
										isok = false;
										return false;
									}
									
									if(null != value && "" != value && undefined != value && "undefined" != value){
										if(value.length > 2000){
											alert("内容不能超过2000个汉字或字符！");
											isok = false;
											return false;
										}
									}
									data[name] = value;
								});
								if(isok){
									confirm("确认发送？",function(data){
										data.location = window.location.href;
										$.ajax({
											url : divhrefcp,
											type : "post",
											data : data,
											success : function(data){
												if(data.success){
													alert("提交成功！我们的工作人员会及时与您联系！");
													$("input[actionid='"+decons.attr("id")+"']").val("");
												}else{
													alert("提交失败！");
												}
											}
										});
									},data);
								}
							});
						}else if("120" == divHrefType || "130" == divHrefType){
							box.click(function(){
								try{
									var newdivhrefcp = divhrefcp;
									if(newdivhrefcp.indexOf("?") != -1){
										newdivhrefcp = newdivhrefcp+"&scrollertype=parent&childname="+childname;
									}else{
										newdivhrefcp = newdivhrefcp+"?scrollertype=parent&childname="+childname;
									}
									var iframex = window.frames[childname];
									var isParent = false;
									if(null == iframex || undefined == iframex){
										isParent = true;
										iframex = window.parent.frames[childname];
									}
									iframex.location.href = newdivhrefcp;
									if(isParent){
										$(window.parent.document).find(".pageElements[data-actived='1']").click();
									}
								}catch(e){
									//alert("找不到对应名称的子级IFRAME");
								}
							});
						}else if("140" == divHrefType){
							box.click(function(){
								history.back();
							});
						}else if("150" == divHrefType){
							box.click(function(){
								window.location.href = divhrefcp;
							});
						}else if("160" == divHrefType){
							box.click(function(){
								try{
									var newdivhrefcp = divhrefcp;
									var iframex = window.frames[childname];
									var isParent = false;
									if(null == iframex || undefined == iframex){
										isParent = true;
										iframex = window.parent.frames[childname];
									}
									iframex.location.href = newdivhrefcp;
								}catch(e){
									//alert("找不到对应名称的子级IFRAME");
								}
							});
						}
						
					}
				}
			}else if("clickshow" == proptext){
				if(!editing){
					//渲染点击效果
					var thisContent = propcontent;
					box.click(function(){
						if(null != thisContent && "" != thisContent && "1001" != thisContent){
							if($(".clickshow").size() != 0){
								var curShow = $($(".clickshow")[0]);
								curShow.css("background-color",curShow.data("ybgcolor"));
								curShow.css("color",curShow.data("ycolor"));
								curShow.css("font-weight",curShow.data("yfontweight"));
								$(".clickshow").removeClass("clickshow");
							}
							
							var deconshtm = box.find(".elementsBox").find(".decons");
							deconshtm.addClass("clickshow");
							var ybgcolor = deconshtm.css("background-color");
							var ycolor = deconshtm.css("color");
							var yfontweight = deconshtm.css("font-weight");
							thisContent = thisContent;
							if("10" == thisContent){
								deconshtm.css("background-color",clickshowcolor);
								deconshtm.css("color",clickcolor);
								deconshtm.css("font-weight",clickfontweight);
							}else if("20" == thisContent){
								deconshtm.css("background-color",clickshowcolor);
								deconshtm.css("color",clickcolor);
								deconshtm.css("font-weight",clickfontweight);
								setTimeout(function(){
									deconshtm.css("background-color",ybgcolor);
									deconshtm.css("color",ycolor);
									deconshtm.css("font-weight",yfontweight);
								},300);
							}else{
								//无
							}
							deconshtm.data("ybgcolor",ybgcolor);
							deconshtm.data("ycolor",ycolor);
							deconshtm.data("yfontweight",yfontweight);
						}
					});
				}
			}else if("sfmrdj" == proptext){
				box.data("sfmrdj",propcontent);
			}else{
				if("width" == proptext){
					if(propcontent.indexOf("h") != -1){
						propcontent = propcontent.replace("h","");
						propcontent = propcontent+"%";
					}else if(propcontent.indexOf("px") == -1){
						propcontent = propcontent/100 * stageWidth;
					}
				}else if("height" == proptext){
					if(propcontent.indexOf("h") != -1){
						propcontent = propcontent.replace("h","");
						propcontent = propcontent+"%";
					}else if(propcontent.indexOf("px") == -1){
						propcontent = propcontent/100 * stageWidth;
					}
				}else if("border-radius" == proptext){
					propcontent = propcontent * stageWidth / parentWidth;
					propcontent = propcontent + "px";
				}else if("position" == proptext){
					if("fixed" == propcontent){
						var nowerTop = box.position().top;
						var maxTop = wheight-box.height();
						if(nowerTop >= maxTop ){
							box.css("bottom","0px");
						}
					}
				}
				//修改父级样式
				box.css(proptext,propcontent);
			} 
		}else if("191" == prop.type){
			var proptext = prop.text;
			var propcontent = prop.content;
			decons.html("");
			var swslides = $("<ul class='sw-slides'></ul>");
			decons.append(swslides);
			if(null != propcontent && "" != propcontent){
				var urls = propcontent.split(";");
				var imgxs = "";
				for(var x = 0; x < urls.length; x++){
					var xurl = showImgPath + urls[x];
					var imgx = "<li class='sw-slide'>" 	
									+"<img src='"+ xurl +"' alt='无法加载'>"  
							  +"</li>";
					imgxs+=imgx;
				}
				swslides.append($(imgxs));
			}
			needrenderSlidebox = true;
		}
	}
	for(var i = 0; i < props.length; i++){
		var prop = props[i];
		if("192" == prop.type){
			var proptext = prop.text;
			var propcontent = prop.content;
			if(null != propcontent && "" != propcontent){
				try{
					var menuInfos = JSON.parse(propcontent);
					parseMenu(boxElem.find(".decons"),menuInfos,box.height(),fontsizeS);
				}catch(e){
					
				}
				
			}
			
		}
	}
	if(needrenderSlidebox){
		setTimeout(function(){
			decons.swipeslider();
		},300);
	}
}

//转换菜单
function parseMenu(menuContainer,menuInfos,boxheight,fontsizeS){
	var nowerHref = $("#websiteeditor_code").val();
	var showPath = $("#websiteeditor_showPath").val();
	var dpadding = 60;
	menuContainer.html("");
	var divPadding = dpadding/100 * boxheight;
	
	for(var x = 0; x < menuInfos.length; x++){
		var menuInfo = menuInfos[x];
		if(nowerHref == menuInfo.pageCode){
			menuInfo.active = true;
		}
		menuInfo.href = showPath+menuInfo.pageCode;
		var divbox = $("<div></div>");
		////type:1-->logo  type:2-->标签  type:3-->跳转按钮  type:4-->下拉按钮  type:5-->下拉选项（跳转页面）
		if("1" == menuInfo.type || 1 == menuInfo.type){
			divbox.addClass("menubox1");
			divbox.addClass("menuboxs");
		}else if("2" == menuInfo.type || 2 == menuInfo.type){
			divbox.addClass("menubox2");
			divbox.addClass("menuboxs");
			var btn = $("<a href='"+menuInfo.href+"'>"+menuInfo.name+"</a>");
			btn.addClass("menubtn2");
			divbox.append(btn);
			menuInfo.active = false;
		}else if("3" == menuInfo.type || 3 == menuInfo.type){
			divbox.addClass("menubox3");
			divbox.addClass("menuboxs");
			var btn = $("<a href='"+menuInfo.href+"'>"+menuInfo.name+"</a>");
			btn.addClass("menubtn3");
			divbox.append(btn);
			
		}else if("4" == menuInfo.type || 4 == menuInfo.type){
			menuInfo.href = "";
			divbox.addClass("menubox4");
			divbox.addClass("menuboxs");
			var divbox2 = $("<div></div>");
			divbox2.addClass("menubox4_1");
			var btn = $("<a href='javascript:void(0)'>"+menuInfo.name+"</a>");
			btn.addClass("menubtn4");
			divbox2.append(btn);
			var triangle = $("<a href='javascript:void(0)'></a>");
			triangle.addClass("bottomTriangle");
			var triangleWidth = (boxheight*0.15)+"px";
			triangle.css("border-top-width",triangleWidth);
			triangle.css("border-left-width",triangleWidth);
			triangle.css("border-right-width",triangleWidth);
			triangle.css("top",(boxheight*0.25)+"px");
			triangle.css("left",(boxheight*0.2)+"px");
			divbox2.append(triangle);
			divbox.append(divbox2);
			if(menuInfo.children){
				var chooseBox = $("<div></div>");
				chooseBox.addClass("menubox4_2");
				chooseBox.css("top",boxheight);
				for(var y = 0; y < menuInfo.children.length; y++){
					var menuInfo5 = menuInfo.children[y];
					menuInfo5.href = showPath+menuInfo5.pageCode;
					if("5" == menuInfo5.type || 5 == menuInfo5.type){
						var divbox5 = $("<div></div>");
						divbox5.addClass("menubox4_2_1");
						divbox5.addClass("menuboxs");;
						var btn5 = $("<a href='"+menuInfo5.href+"'>"+menuInfo5.name+"</a>");
						btn5.addClass("menubtn5");
						divbox5.append(btn5);
						if(nowerHref == menuInfo5.pageCode){
							menuInfo.active = true;
						}else{
							divbox5.addClass("notcurbox");
						}
						chooseBox.append(divbox5);
					}
				}
				divbox.append(chooseBox);
			}
			
		}
		
		var lineHeight = boxheight;
		if(null != fontsizeS){
			lineHeight = lineHeight + fontsizeS+(boxheight*0.7);
		}
		divbox.css("line-height",(lineHeight/2)+"px");
		
		divbox.css("padding-left",divPadding+"px");
		divbox.css("padding-right",divPadding+"px");
		if(menuInfo.active){
			divbox.addClass("curmenu");
		}
		menuContainer.append(divbox);
	}
}